cmake_minimum_required(VERSION 3.8)
project(my_package_cpp)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(example_interfaces REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(my_package_cpp REQUIRED)

# 注意命名规则首字母必须大写 生成的头文件会变化  TestUser.srv 会变成 test_user.h
rosidl_generate_interfaces(${PROJECT_NAME}
  "srv/UserTest.srv"
  "msg/UserTest.msg"
  "action/Example.action"
  DEPENDENCIES builtin_interfaces
)

include_directories(~/ros2_ws/build/my_package_cpp/rosidl_generator_cpp/)
include_directories(/opt/ros/humble/include/example_interfaces/)
include_directories(/opt/ros/humble/include/rclcpp_action/)

add_executable(my_node src/my_node.cpp)
target_include_directories(my_node PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>)
target_compile_features(my_node PUBLIC c_std_99 cxx_std_17)  # Require C99 and C++17

add_executable(1pub_node src/1pub.cpp)
ament_target_dependencies(1pub_node rclcpp std_msgs )


add_executable(1sub_node src/1sub.cpp)
ament_target_dependencies(1sub_node  rclcpp std_msgs)

add_executable(2srv_node src/2srv.cpp)
ament_target_dependencies(2srv_node rclcpp std_msgs example_interfaces )

add_executable(2client_node src/2client.cpp)
ament_target_dependencies(2client_node rclcpp std_msgs example_interfaces )

add_executable(3param_node src/3param.cpp)
ament_target_dependencies(3param_node rclcpp std_msgs)

add_executable(4action_server_node src/4action_server.cpp)
ament_target_dependencies(4action_server_node rclcpp std_msgs example_interfaces rclcpp_action)

add_executable(4action_client_node src/4action_client.cpp)
ament_target_dependencies(4action_client_node rclcpp std_msgs example_interfaces rclcpp_action)

add_executable(5tf_broadcast_node src/5tf_broadcast.cpp)
ament_target_dependencies(5tf_broadcast_node rclcpp std_msgs rclcpp_action tf2_ros geometry_msgs)

add_executable(5tf_listener_node src/5tf_listener.cpp)
ament_target_dependencies(5tf_listener_node rclcpp std_msgs rclcpp_action tf2_ros geometry_msgs)  


install(TARGETS
  my_node
  1pub_node
  1sub_node
  2srv_node
  2client_node
  3param_node
  4action_server_node
  4action_client_node
  5tf_broadcast_node
  5tf_listener_node
  DESTINATION lib/${PROJECT_NAME})

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()
